﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Lead2012.Business;
using Lead2012.Models;
using Lead2012.ViewModels;
using Lead2012.Repository;

namespace Lead2012.Controllers
{
    public class LeadStatisticController : BaseController
    {
        // Create an instance of repository
        LeadStatisticManagementRepository repository = new LeadStatisticManagementRepository();

        [Authorize(Roles = "Administrator")]
        public ActionResult Index(string chartType, string filterType, string filterOptions)
        {
            LeadStatisticViewModel model = new LeadStatisticViewModel();

            // Setup model
            model.PageType = "Menu";
            SetupCommon(model, string.Empty, "Name");

            // Get all leads
            model.StatisticType = "Milestone";
            model.ChartType = string.IsNullOrEmpty(chartType) ? "Bar" : chartType; // Chart type 'Bar'|'Line'|'Pie'|'Growth'
            model.FilterType = string.IsNullOrEmpty(filterType) ? "year" : filterType; // Year, Month, Range
            model.FilterOption = string.IsNullOrEmpty(filterOptions) ? DateTime.Now.Year.ToString() : filterOptions; // '2001' || '02' | '22-2-2013 -> 30-2-2013'
            repository.GetStatisticModel(ref model);

            return View(model);
        }

        [Authorize(Roles = "Administrator")]
        public ActionResult Statuses(string chartType, string filterType, string filterOptions)
        {
            LeadStatisticViewModel model = new LeadStatisticViewModel();

            // Setup model
            model.PageType = "Menu";
            SetupCommon(model, string.Empty, "Name");

            // Get all leads
            model.StatisticType = "Status";
            model.ChartType = string.IsNullOrEmpty(chartType) ? "Bar" : chartType; // Chart type 'Bar'|'Line'|'Pie'|'Growth'
            model.FilterType = string.IsNullOrEmpty(filterType) ? "year" : filterType; // Year, Month, Range
            model.FilterOption = string.IsNullOrEmpty(filterOptions) ? DateTime.Now.Year.ToString() : filterOptions; // '2001' || '02' | '22-2-2013 -> 30-2-2013'
            repository.GetStatisticModel(ref model);

            return View(model);
        }

        [Authorize(Roles = "Administrator")]
        public ActionResult Sources(string chartType, string filterType, string filterOptions)
        {
            LeadStatisticViewModel model = new LeadStatisticViewModel();

            // Setup model
            model.PageType = "Menu";
            SetupCommon(model, string.Empty, "Name");

            // Get all leads
            model.StatisticType = "Source";
            model.ChartType = string.IsNullOrEmpty(chartType) ? "Bar" : chartType; // Chart type 'Bar'|'Line'|'Pie'|'Growth'
            model.FilterType = string.IsNullOrEmpty(filterType) ? "year" : filterType; // Year, Month, Range
            model.FilterOption = string.IsNullOrEmpty(filterOptions) ? DateTime.Now.Year.ToString() : filterOptions; // '2001' || '02' | '22-2-2013 -> 30-2-2013'
            repository.GetStatisticModel(ref model);

            return View(model);
        }

        [Authorize(Roles = "Administrator")]
        public ActionResult Users(string chartType, string filterType, string filterOptions)
        {
            LeadStatisticViewModel model = new LeadStatisticViewModel();

            // Setup model
            model.PageType = "Menu";
            SetupCommon(model, string.Empty, "Name");

            // Get all leads
            model.StatisticType = "User";
            model.ChartType = string.IsNullOrEmpty(chartType) ? "Bar" : chartType; // Chart type 'Bar'|'Line'|'Pie'|'Growth'
            model.FilterType = string.IsNullOrEmpty(filterType) ? "year" : filterType; // Year, Month, Range
            model.FilterOption = string.IsNullOrEmpty(filterOptions) ? DateTime.Now.Year.ToString() : filterOptions; // '2001' || '02' | '22-2-2013 -> 30-2-2013'
            repository.GetStatisticModel(ref model);

            return View(model);
        }
    }
}
